<style type="text/css">
.grid-view .status-column { width: 2% !important; }
</style>

<div class="form wide">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'export-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
        'afterValidate'=>"js:function(form,data,hasError){
            if (!hasError)
            {
                var page_ids = new Array();
                $('#pages-grid table.items td.checkbox-col :checkbox').each(function(){
                    if (this.checked == true)
                        page_ids.push(this.value);
                });
                if (page_ids.length <= 0)
                {
                    alert('Please select at least a page !');
                    return false;
                }
                page_ids = page_ids.join(',');
                $('#pageIds').val(page_ids);
                return true;
            }
            return false;
        }"
    )
));

$cs = Yii::app()->clientScript;
$baseScriptUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';
$cs->registerCssFile($baseScriptUrl.'/styles.css');
$url=CHtml::asset(Yii::getPathOfAlias('system.web.widgets.pagers.pager').'.css');
$cs->registerCssFile($url);
$cs->registerCoreScript('bbq');
$cs->registerScriptFile($baseScriptUrl.'/jquery.yiigridview.js',CClientScript::POS_END);
?>
    <input type="hidden" id="pageIds" name="pageIds" />
    <div class="row">
        <label>Choose a workflow :</label>
        <?php
        $workflows = Workflow::model()->findAll();
        echo CHtml::dropDownList('workflowId',$selectedWorkFlowId,CHtml::listData($workflows,'id','name'));
        ?>
    </div>
    
    <div id="page-list-section"></div>
    
    <div class="row buttons">
        <input type="submit" id="btnExport" value="Export" />
    </div>
<?php $this->endWidget(); ?>
</div>

<script type="text/javascript">
$('#workflowId').change(function(){
    var workflowId = $(this).val();
    if (workflowId != '')
    {
        $.get(
            '/index.php?r=Cms/admin/page/pagesByWorkflow',
            {
                'workflow_id' : workflowId
            },
            function(html)
            {
                $('#page-list-section').html(html);    
            }
        );
    }
    else
    {
        $('#page-list-section').html('');
    }        
});
$(document).ready(function(){
    $('#workflowId').trigger('change');
});

$('#btnExport').click(function(){
    var page_ids = new Array();
    $('#pages-grid table.items td.checkbox-col :checkbox').each(function(){
        if (this.checked == true)
            page_ids.push(this.value);
    });
    if (page_ids.length <= 0)
    {
        alert('Please select at least a page !');
        return false;
    }
    page_ids = page_ids.join(',');
    $('#pageIds').val(page_ids);
    $('#export-form').submit();        
});
</script>